<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/%E6%AD%A6%E6%B1%8932x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/%E6%AD%A6%E6%B1%8916x16.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib1/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="/lib1/pace/pace-theme-center-simple.min.css">
  <script src="/lib1/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"example.com","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="前言承接上一篇文章的内容，在总结完vue的初始化、双向绑定的源码之后，这一篇打算写写vue批量异步更新策略与虚拟DOM、diff算法，由于个人水平有限，可能也只能以一个新手的角度进行分析，不会太过于深入。 异步更新队列vue高效的秘诀是批量、异步的更新策略；在一次更新周期之内，可能会有很多组件发生变化，因此需要一次将所有变化全部侦听到，每次都将更新的Watcher放在更新队列中，再一次性更新DOM">
<meta property="og:type" content="article">
<meta property="og:title" content="vue源码分析(二)">
<meta property="og:url" content="http://example.com/2021/03/17/vue%E6%BA%90%E7%A0%81/vue%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90(%E4%BA%8C)/index.html">
<meta property="og:site_name" content="Technological Blog">
<meta property="og:description" content="前言承接上一篇文章的内容，在总结完vue的初始化、双向绑定的源码之后，这一篇打算写写vue批量异步更新策略与虚拟DOM、diff算法，由于个人水平有限，可能也只能以一个新手的角度进行分析，不会太过于深入。 异步更新队列vue高效的秘诀是批量、异步的更新策略；在一次更新周期之内，可能会有很多组件发生变化，因此需要一次将所有变化全部侦听到，每次都将更新的Watcher放在更新队列中，再一次性更新DOM">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-03-17T04:18:39.000Z">
<meta property="article:modified_time" content="2021-04-02T08:30:01.011Z">
<meta property="article:author" content="Li Yudong">
<meta property="article:tag" content="vue源码">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://example.com/2021/03/17/vue%E6%BA%90%E7%A0%81/vue%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90(%E4%BA%8C)/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>vue源码分析(二) | Technological Blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Technological Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">IT小白的成长之旅</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="tags fa-fw"></i>标签<span class="badge">18</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="th fa-fw"></i>分类<span class="badge">14</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="archive fa-fw"></i>归档<span class="badge">95</span></a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

  <a href="https://github.com/tiarmor1" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/03/17/vue%E6%BA%90%E7%A0%81/vue%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90(%E4%BA%8C)/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/author.jpg">
      <meta itemprop="name" content="Li Yudong">
      <meta itemprop="description" content="">
    </span>
    
    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Technological Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          vue源码分析(二)
        </h1>
    
        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
    
              <time title="创建时间：2021-03-17 12:18:39" itemprop="dateCreated datePublished" datetime="2021-03-17T12:18:39+08:00">2021-03-17</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-04-02 16:30:01" itemprop="dateModified" datetime="2021-04-02T16:30:01+08:00">2021-04-02</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/VUE/" itemprop="url" rel="index"><span itemprop="name">VUE</span></a>
                </span>
            </span>
    
          
    
        </div>
      </header>
    
    
    
    
    <div class="post-body" itemprop="articleBody">
    
      
        <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>承接上一篇文章的内容，在总结完vue的初始化、双向绑定的源码之后，这一篇打算写写vue批量异步更新策略与虚拟DOM、diff算法，由于个人水平有限，可能也只能以一个新手的角度进行分析，不会太过于深入。</p>
<h1 id="异步更新队列"><a href="#异步更新队列" class="headerlink" title="异步更新队列"></a>异步更新队列</h1><p>vue高效的秘诀是批量、异步的更新策略；在一次更新周期之内，可能会有很多组件发生变化，因此需要一次将所有变化全部侦听到，每次都将更新的Watcher放在更新队列中，再一次性更新DOM。这个异步更新队列的关键在于事件循环的机制，</p>
<p>宏任务：代表一个个离散的、独立工作单元，浏览器每完成一个宏任务，在下一个宏任务执行开始前会对页面进行重新渲染，会刷新一次。宏任务主要包括：创建主文档对象、解析HTML、各种事件、定时器。如果在一次宏任务执行完之后，事件循环队列中存在微任务，则会一次性将所有的微任务全部执行，将微任务队列清空之后再重新渲染。微任务主要包括：promise回调函数、DOM发生变化。</p>
<p>vue中如何利用事件队列：用微任务来实现刷新队列这件事，在宏任务执行完之后，全部执行微任务队列，这样把所有的watcher都推出队列中加以执行。</p>
<h2 id="vue的具体实现"><a href="#vue的具体实现" class="headerlink" title="vue的具体实现"></a>vue的具体实现</h2><p>异步：只要侦听到数据变化，Vue将会开启一个队列，并缓存在同一事件循环中发生的所有数据变更。</p>
<p>批量：如果一个watcher被多次触发，只会被推入到队列中一次。去重对于避免不必要的计算和DOM操作是非常重要的。然后，在下一个事件循环的tick中，Vue刷新队列并执行实际工作。</p>
<p>异步策略：Vue在内部对异步队列尝试使用原生的Promise.then、MutationObserver和setImmediate，只有在执行环境不支持时，则会采用setTimeOut来代替。</p>
<h2 id="整体流程"><a href="#整体流程" class="headerlink" title="整体流程"></a>整体流程</h2><h3 id="core-observer-watcher-js"><a href="#core-observer-watcher-js" class="headerlink" title="core\observer\watcher.js"></a><strong>core\observer\watcher.js</strong></h3><p>dep.notify()之后watcher执行更新，执行入队操作，在Watcher类中有一个方法upDate()，执行queueWatcher()。</p>
<h3 id="core-observer-scheduler-js"><a href="#core-observer-scheduler-js" class="headerlink" title="core\observer\scheduler.js"></a><strong>core\observer\scheduler.js</strong></h3><p>queueWatcher()执行watcher入队操作，只有在不重复时才会采取入队操作。</p>
<h3 id="core-util-next-tick-js"><a href="#core-util-next-tick-js" class="headerlink" title="core\util\next-tick.js"></a><strong>core\util\next-tick.js</strong></h3><p>nextTick(flushSchedulerQueue) 按照特定异步策略执行队列操作。同时根据当前浏览器支持的类型，来判断通过哪种方式来实现异步更新。watcher中update执行三次，但run仅执行一次</p>
<h1 id="虚拟DOM"><a href="#虚拟DOM" class="headerlink" title="虚拟DOM"></a>虚拟DOM</h1><p>虚拟DOM是对DOM的JS抽象表示，它们是JS对象，能够描述DOM结构和关系，应用的各种状态会作用与虚拟DOM，最终映射到DOM上。</p>
<p>JS操作 = reactive =&gt; 虚拟DOM = patch =&gt; DOM = events =&gt; JS操作。虚拟DOM其实是用JS操作数据时的中间层，reactive即为数据的响应式，patch即为后续的补丁操作与diff算法；其关键作用是让我们直接跟数据去打交道，而不用去操作DOM。</p>
<h2 id="优点"><a href="#优点" class="headerlink" title="优点"></a>优点</h2><p>1、轻量且快速：当它们发生变化时通过新旧虚拟DOM对比可以得到最小DOM操作量，从而提升性能。</p>
<p>2、跨平台性：将虚拟DOM更新转换成不同运行时的特殊操作，从而实现跨平台的效果。</p>
<p>3、兼容性：还可以加入兼容性代码来增强操作的兼容性。</p>
<h2 id="必要性"><a href="#必要性" class="headerlink" title="必要性"></a>必要性</h2><p>在vue1.0中每一个绑定都会有一个Watcher，因此当数据量过大时，则绑定过多、影响性能。这就是所谓的细粒度的数据变化侦测，在vue2.0中选择了中等细粒度的解决方案，每一个组件才有一个watcher实例。虽然不能马上知道数据修改的情况，但这样可以在每次状态变化时通知到组件，再通过引入虚拟DOM去进行对比和渲染。</p>
<h2 id="整体流程-1"><a href="#整体流程-1" class="headerlink" title="整体流程"></a>整体流程</h2><h3 id="core-instance-lifecycle-js"><a href="#core-instance-lifecycle-js" class="headerlink" title="core/instance/lifecycle.js**"></a>core/instance/lifecycle.js**</h3><p>**mountComponent() **</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 定义更新函数 </span></span><br><span class="line"><span class="keyword">const</span> updateComponent = <span class="function"><span class="params">()</span> =&gt;</span> &#123; </span><br><span class="line">    <span class="comment">// 实际调用是在lifeCycleMixin中定义的_update和renderMixin中定义的_render</span></span><br><span class="line">    vm._update(vm._render(), hydrating) </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>**update()**：负责更新dom，转换vnode为dom。</p>
<h3 id="render-core-instance-render-js"><a href="#render-core-instance-render-js" class="headerlink" title="_render core/instance/render.js"></a><strong>_render core/instance/render.js</strong></h3><p>生成虚拟dom</p>
<h3 id="platforms-web-runtime-index-js"><a href="#platforms-web-runtime-index-js" class="headerlink" title="platforms/web/runtime/index.js"></a><strong>platforms/web/runtime/index.js</strong></h3><p><strong>patch</strong>()函数可根据平台的不同，生成特有的代码。patch是createPatchFunction的返回值，传递nodeOps和modules是web平台特别实现</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">export</span> <span class="keyword">const</span> patch: <span class="built_in">Function</span> = createPatchFunction(&#123; nodeOps, modules &#125;)</span><br></pre></td></tr></table></figure>

<p>watcher.run() =&gt; componentUpdate() =&gt; render() =&gt; update() =&gt; patch()</p>
<h2 id="patch实现"><a href="#patch实现" class="headerlink" title="patch实现"></a>patch实现</h2><p>首先进行树级别比较，可能有三种情况：增删改。</p>
<p>1、new VNode不存在就删；</p>
<p>2、old VNode不存在就增；</p>
<p>3、都存在就执行diff执行更新</p>
<p>patch遵循的逻辑是=&gt; 深度优先、同级比较。</p>
<p>即当新老节点都有孩子时，则继续往子节点进行比较，同样这样的比较过程是递归的。</p>
<p>比较两个VNode，包括三种类型操作：<strong>属性更新、文本更新、子节点更新</strong></p>
<p>具体规则如下：</p>
<p>1、新老节点均有children子节点，则对子节点进行diff操作，调用updateChildren()，这里其实就是vue的diff算法。</p>
<p>2、如果老节点没有子节点而新节点有子节点，先清空老节点的文本内容，然后为其新增子节点。</p>
<p>3、当新节点没有子节点而老节点有子节点的时候，则移除该节点的所有子节点。</p>
<p>4、当新老节点都无子节点的时候，只是文本的替换。</p>
<h3 id="updateChildren"><a href="#updateChildren" class="headerlink" title="updateChildren()"></a>updateChildren()</h3><p>updateChildren主要作用是用一种较高效的方式比对新旧两个VNode的children得出最小操作补丁。执行一个双循环是传统方式，vue中针对web场景特点做了特别的算法优化。我们大部分的操作往往是前后节点的改变，很少直接在中间节点处进行大量修改，因此重点关注首尾进行比较。</p>
<p>在新老两组VNode节点的左右头尾两侧都有一个变量标记，在<strong>遍历过程中这几个变量都会向中间靠拢</strong>。 </p>
<p>当<strong>oldStartIdx &gt; oldEndIdx</strong>或者<strong>newStartIdx &gt; newEndIdx</strong>时结束循环。遍历的规则如下：</p>
<p>首先，oldStartVnode、oldEndVnode与newStartVnode、newEndVnode<strong>两两交叉比较</strong>，共有4种比较方法。</p>
<p>1、当 oldStartVnode和newStartVnode 或者 oldEndVnode和newEndVnode 满足sameVnode，直接将该VNode节点进行patchVnode即可，不需再遍历就完成了一次循环。</p>
<p>2、如果oldStartVnode与newEndVnode满足sameVnode。说明oldStartVnode已经跑到了oldEndVnode后面去了，进行patchVnode的同时还需要将真实DOM节点移动到oldEndVnode的后面。</p>
<p>3、如果oldEndVnode与newStartVnode满足sameVnode，说明oldEndVnode跑到了oldStartVnode的前面，进行patchVnode的同时要将oldEndVnode对应DOM移动到oldStartVnode对应DOM的前面。</p>
<p>4、如果以上情况均不符合，则在old VNode中找与newStartVnode满足sameVnode的vnodeToMove，若存在执行patchVnode，同时将vnodeToMove对应DOM移动到oldStartVnode对应的DOM的前面。当然也有可能newStartVnode在old VNode节点中找不到一致的key，或者是即便key相同却不是sameVnode，这个时候会调用createElm创建一个新的DOM节点。</p>
<p>至此循环结束，但是我们还需要处理剩下的节点。</p>
<p>1、当结束时oldStartIdx &gt; oldEndIdx，这个时候旧的VNode节点已经遍历完了，但是新的节点还没有。说明了新的VNode节点实际上比老的VNode节点多，需要将剩下的VNode对应的DOM插入到真实DOM中，此时调用addVnodes（批量调用createElement接口）。</p>
<p>2、但是，当结束时newStartIdx &gt; newEndIdx时，说明新的VNode节点已经遍历完了，但是老的节点还有剩余，需要从文档中删 的节点删除。</p>
<p>上面的遍历查找方法就是diff算法的逻辑。</p>

    </div>
    
    
    
    
    <div>
      
        <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>

      
    </div>
        <div class="reward-container">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button onclick="var qr = document.getElementById('qr'); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
      
      <div style="display: inline-block;">
        <img src="/images/alipay.png" alt="Li Yudong 支付宝">
        <p>支付宝</p>
      </div>

  </div>
</div>

        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>Li Yudong
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://example.com/2021/03/17/vue%E6%BA%90%E7%A0%81/vue%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90(%E4%BA%8C)/" title="vue源码分析(二)">http://example.com/2021/03/17/vue源码/vue源码分析(二)/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

    
      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/vue%E6%BA%90%E7%A0%81/" rel="tag"># vue源码</a>
          </div>
    
        

    
        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/03/16/vue%E6%BA%90%E7%A0%81/vue%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90(%E4%B8%80)/" rel="prev" title="vue源码分析(一)">
      <i class="fa fa-chevron-left"></i> vue源码分析(一)
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/03/17/vue%E6%BA%90%E7%A0%81/vue%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90(%E4%B8%89)/" rel="next" title="vue源码分析(三)">
      vue源码分析(三) <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#异步更新队列"><span class="nav-number">2.</span> <span class="nav-text">异步更新队列</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#vue的具体实现"><span class="nav-number">2.1.</span> <span class="nav-text">vue的具体实现</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#整体流程"><span class="nav-number">2.2.</span> <span class="nav-text">整体流程</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#core-observer-watcher-js"><span class="nav-number">2.2.1.</span> <span class="nav-text">core\observer\watcher.js</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#core-observer-scheduler-js"><span class="nav-number">2.2.2.</span> <span class="nav-text">core\observer\scheduler.js</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#core-util-next-tick-js"><span class="nav-number">2.2.3.</span> <span class="nav-text">core\util\next-tick.js</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#虚拟DOM"><span class="nav-number">3.</span> <span class="nav-text">虚拟DOM</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#优点"><span class="nav-number">3.1.</span> <span class="nav-text">优点</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#必要性"><span class="nav-number">3.2.</span> <span class="nav-text">必要性</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#整体流程-1"><span class="nav-number">3.3.</span> <span class="nav-text">整体流程</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#core-instance-lifecycle-js"><span class="nav-number">3.3.1.</span> <span class="nav-text">core&#x2F;instance&#x2F;lifecycle.js**</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#render-core-instance-render-js"><span class="nav-number">3.3.2.</span> <span class="nav-text">_render core&#x2F;instance&#x2F;render.js</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#platforms-web-runtime-index-js"><span class="nav-number">3.3.3.</span> <span class="nav-text">platforms&#x2F;web&#x2F;runtime&#x2F;index.js</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#patch实现"><span class="nav-number">3.4.</span> <span class="nav-text">patch实现</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#updateChildren"><span class="nav-number">3.4.1.</span> <span class="nav-text">updateChildren()</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Li Yudong"
      src="/images/author.jpg">
  <p class="site-author-name" itemprop="name">Li Yudong</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">95</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">18</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/tiarmor1" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;tiarmor1" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:1157019137@qq.com" title="E-Mail → mailto:1157019137@qq.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>
  <div class="cc-license motion-element" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 2020 – 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Li Yudong</span>
</div>

        








      </div>
    </footer>
  </div>

  
  
  <script color='0,0,0' opacity='0.5' zIndex='-1' count='150' src="/lib1/canvas-nest/canvas-nest.min.js"></script>
  <script src="/lib1/anime.min.js"></script>
  <script src="/lib1/velocity/velocity.min.js"></script>
  <script src="/lib1/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  

  
   <canvas class="fireworks" style="position: fixed;left: 0;top: 0;z-index: 1; pointer-events: none;" ></canvas> 
   <script type="text/javascript" src="//cdn.bootcss.com/animejs/2.2.0/anime.min.js"></script> 
   <script type="text/javascript" src="/js/fireworks.js"></script>
  
</body>
</html>

